﻿package plugin.npcDialog.ui.panels.active
{
    import com.greensock.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import morn.core.utils.*;
    import plugin.bagN.*;
    import uiresource.npcdialogs.*;
    import view.*;
    import view.uilt.*;

    public class HjGame extends HjUI implements INpcDialogContent
    {
        private var npcDelivers:Array;
        private var tweenMax:TweenMax;
        private var user:Object;
        private var rein:int;
        private var level:int;

        public function HjGame()
        {
            this.npcDelivers = ConfigDictionary.data.deliver[1216];
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            list.mouseHandler = new Handler(this.doMouse);
            goumai.clickHandler = new Handler(this.toGm);
            return;
        }// end function

        private function toGm() : void
        {
            var _loc_1:* = this.localToGlobal(new Point(195, 260));
            DialogMgr.instance.open(AppDialog.SC_BUY, {storeId:445, showPosition:_loc_1});
            return;
        }// end function

        private function doMouse(event:MouseEvent, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            if (event.type == MouseEvent.CLICK)
            {
                _loc_3 = this.npcDelivers[param2];
                this.user = UserData.getUserData();
                this.rein = this.user.rein;
                this.level = this.user.level;
                _loc_4 = this.doCheck(_loc_3);
                if (_loc_4.canIn)
                {
                    _loc_5 = ItemUilt.getAllCount(240202068);
                    if (_loc_5 > 0)
                    {
                        PluginManager.instance.sendToServer("bag", CMDBag.NPCDeliver, _loc_3.id);
                        PluginManager.instance.closePlugin("npcdialog");
                    }
                    else
                    {
                        _loc_6 = ConfigDictionary.data.item;
                        WarningManager.show(31, [_loc_6[240202068].name]);
                    }
                }
                else
                {
                    WarningManager.show(_loc_4.warning.id, _loc_4.warning.param);
                }
            }
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            this.removeTween();
            return;
        }// end function

        public function removeTween() : void
        {
            if (this.tweenMax)
            {
                this.tweenMax.kill();
                this.tweenMax = null;
                ObjectUtils.clearFilter(goumai, GlowFilter);
            }
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            this.user = UserData.getUserData();
            this.rein = this.user.rein;
            this.level = this.user.level;
            list.array = this.npcDelivers;
            list.renderHandler = new Handler(this.npcRender);
            this.updatebag();
            return;
        }// end function

        private function npcRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:LinkButton = null;
            var _loc_5:Object = null;
            if (param2 < list.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("txt_layer") as LinkButton;
                _loc_5 = this.doCheck(_loc_3, true);
                _loc_4.labelColors = _loc_5.color;
                _loc_4.label = _loc_3.nameshow + "(" + _loc_5.msg + ")";
            }
            return;
        }// end function

        public function doCheck(param1:Object, param2:Boolean = false) : Object
        {
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:Boolean = false;
            var _loc_11:Boolean = false;
            var _loc_12:int = 0;
            var _loc_13:int = 0;
            var _loc_14:int = 0;
            var _loc_3:* = param1.level.split("#");
            var _loc_4:String = "0x736963,0x736963,0x736963,0x736963";
            var _loc_5:String = "";
            if (_loc_3.length > 1)
            {
                _loc_7 = _loc_3[0];
                _loc_8 = _loc_7 / 1000;
                _loc_9 = _loc_7 % 1000;
                _loc_10 = true;
                _loc_11 = false;
                if (this.rein < _loc_8)
                {
                    _loc_10 = false;
                    _loc_6 = {id:39, param:[_loc_8]};
                }
                else if (this.rein == _loc_8)
                {
                    if (this.level < _loc_9)
                    {
                        _loc_10 = false;
                        _loc_6 = {id:38, param:[_loc_9]};
                    }
                }
                _loc_12 = _loc_3[1];
                _loc_13 = _loc_12 / 1000;
                _loc_14 = _loc_12 % 1000;
                if (_loc_10)
                {
                    if (this.rein <= _loc_13)
                    {
                        if (this.level <= _loc_14)
                        {
                            _loc_4 = "0x54B436,0xefd742,0x54b436,0xefd742";
                            _loc_11 = true;
                        }
                        else
                        {
                            _loc_6 = {id:121, param:null};
                        }
                    }
                    else
                    {
                        _loc_6 = {id:122, param:null};
                    }
                }
                if (param2)
                {
                    if (_loc_13 == 0)
                    {
                        if (_loc_9 == 1)
                        {
                            _loc_5 = _loc_14 + "级以下";
                        }
                        else
                        {
                            _loc_5 = _loc_9 + "级以上";
                        }
                    }
                    else if (_loc_8 == 0 && _loc_9 > 1)
                    {
                        _loc_5 = _loc_9 + "级以上-" + _loc_13 + "转";
                    }
                    else
                    {
                        _loc_5 = _loc_8 + "转-" + _loc_13 + "转";
                    }
                }
            }
            else
            {
                _loc_7 = _loc_3[0];
                _loc_8 = _loc_7 / 1000;
                _loc_9 = _loc_7 % 1000;
                _loc_10 = true;
                _loc_11 = false;
                if (this.rein < _loc_8)
                {
                    _loc_6 = {id:39, param:[_loc_8]};
                }
                else if (this.rein == _loc_8)
                {
                    if (this.level < _loc_9)
                    {
                        _loc_6 = {id:38, param:[_loc_9]};
                    }
                    else
                    {
                        _loc_4 = "0x54B436,0xefd742,0x54b436,0xefd742";
                        _loc_11 = true;
                    }
                }
                else
                {
                    _loc_4 = "0x54B436,0xefd742,0x54b436,0xefd742";
                    _loc_11 = true;
                }
                _loc_5 = _loc_8 + "转以上";
            }
            return {color:_loc_4, msg:_loc_5, canIn:_loc_11, warning:_loc_6};
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            return;
        }// end function

        public function updatebag() : void
        {
            this.removeTween();
            var _loc_1:* = ConfigDictionary.data.item;
            var _loc_2:* = ItemUilt.getAllCount(240202068);
            txt_need.text = "消耗" + _loc_1[240202068].name + "：<font color=\'#53B436\'>1</font>个(拥有<font color=\'#" + (_loc_2 > 0 ? ("53B436") : ("c72514")) + "\'> " + _loc_2 + " </font>个)";
            if (_loc_2 > 0)
            {
                this.removeTween();
                goumai.visible = false;
            }
            else
            {
                this.tweenMax = TweenMax.to(goumai, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                goumai.visible = true;
            }
            return;
        }// end function

    }
}
